﻿using System;
using System.IO;
using System.Net;

namespace sync.Library
{
    class sTemp
    {
        #region "old write from list to file"
        /* private void writeToLogFile()//write listChange to log.ini
        {
            sFileMethods fl = new sFileMethods();
            if (fl.IsFileLocked(logFile))
                return;
            if (listChange.Count > 0)
            {
                List<string> listTemp = listChange;
                string changeType, line;
                try
                {
                    for (int i = 0; i < listTemp.Count; i++)
                    {
                        line = listTemp[i];
                        if (line.Contains("|OFP|"))
                            changeType = line.Substring(line.LastIndexOf("|CT|") + 4, line.LastIndexOf("|OFP|") - line.LastIndexOf("|CT|") - 4);
                        else
                        {
                            changeType = line.Substring(line.LastIndexOf("|CT|") + 4, line.LastIndexOf("|FP|") - line.LastIndexOf("|CT|") - 4);
                        }
                        if (changeType == "Created")
                        {
                            string fullPath = line.Substring(line.LastIndexOf("|FP|") + 4, line.LastIndexOf("|FN|") - line.LastIndexOf("|FP|") - 4);
                            string fileName = line.Substring(line.LastIndexOf("|FN|") + 4, line.Length - line.LastIndexOf("|FN|") - 4);
                            if (Directory.Exists(fullPath))
                            {
                                if (File.GetAttributes(fullPath) == FileAttributes.Directory)
                                {
                                    if (Directory.GetDirectories(fullPath).Length > 0 || Directory.GetFiles(fullPath).Length > 0)
                                        thrdCopyFolder(fullPath);
                                }
                            }
                        }

                        File.AppendAllText(logFile, Environment.NewLine + listChange[i]);
                        listChange.Remove(listTemp[i]);
                    }
                }
                catch (Exception ex)
                {
                    showNotify(lineNB() + "\n" + ex.Message);
                }
            }
            if (listChange.Count == 0)
                return;
            //Thread.Sleep(3000);
        }
        private void writeTologSV()
        {
            sFileMethods fl = new sFileMethods();
            if (fl.IsFileLocked(logSVFile))
                return;
            int t = listlogSV.Count;
            List<string> listTmp = listlogSV;
            if (listlogSV.Count > 0)
            {
                try
                {
                    for (int i = 0; i < t; i++)
                    {
                        string s = listlogSV[0];
                        File.AppendAllText(logSVFile, Environment.NewLine + s);
                        listlogSV = listlogSV.Where(w => w != s).ToList();
                    }
                }
                catch (Exception ex)
                {
                    showNotify(lineNB() + "\n" + ex.Message);
                }
            }
            if (listlogSV.Count == 0)
                return;
        } */
        #endregion
        private void upLoad1File(string pathSV, string fileName, string fullPathCL)
        {
            FileStream fileStream = File.OpenRead(fullPathCL);
            Byte[] bt = File.ReadAllBytes(fullPathCL);
        }
        public void Upload()
        {
            WebClient wc = new WebClient();
            wc.UploadDataCompleted += new UploadDataCompletedEventHandler(this.completed);
            wc.UploadProgressChanged += new UploadProgressChangedEventHandler(this.progress);
            //byte[] datas = File.ReadAllBytes(@"E:\Sync\Client\h.txt");
            wc.UploadFileAsync(new Uri(@"https://api-content.dropbox.com/1/files_put/dropbox/h.txt?mute=1&oauth_consumer_key=blglx3u2bqm0je5&oauth_nonce=4555992&oauth_token=nhanjusfqv14h2z&oauth_timestamp=1368699142&oauth_signature=ss27q9hcd9zqayr%26hf5q5co1uu1vuxj&oauth_signature_method=PLAINTEXT&oauth_version=1.0&overwrite=false"), "PUT", @"E:\Sync\Client\h.txt");

        }
        private void completed(object sender, UploadDataCompletedEventArgs e)
        {

            string rez = System.Text.Encoding.ASCII.GetString(e.Result);
            Console.WriteLine("\r\n\r\n--------------------------------------------");
            Console.WriteLine(rez);

        }

        private void progress(object sender, UploadProgressChangedEventArgs e)
        {
            Console.WriteLine ("sent : " + e.BytesSent.ToString() + @"/" + e.TotalBytesToSend.ToString() + " percent : " + e.ProgressPercentage.ToString());
        }
    }
}
